package com.car.controller.department;

import com.car.entity.Car;
import com.car.entity.Department;
import com.car.service.department.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ClassName: DepartmentController
 * @Description:
 * @Author 余全盛
 * @Date: 2021/12/2 14:57
 */
@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/toDeptInfo")
    public ModelAndView toDeptInfo(@RequestParam int deptId) {
        ModelAndView mv = new ModelAndView("Dept-info");
        Department department=departmentService.getDepartmentById(deptId);
        mv.addObject("dept",department);
        return mv;
    }
    @RequestMapping("/getAllDepartments")
    @ResponseBody
    public List<Department> getAllDepartments() {
        List<Department> departments = departmentService.selectAllDepartments();
        return departments;
    }

    @RequestMapping("/getDepartmentById")
    @ResponseBody
    public Department getDepartmentById(Integer departmentId){
        Department department = departmentService.getDepartmentById(departmentId);
        return department;
    }
}
